<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增标准农事')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ncWork-add">
        <input id="stageId" name="stageId" th:value="${stageId}" type="hidden">
        <input id="standardId" name="standardId" th:value="${standardId}" type="hidden">
        <input id="workDetail" name="workDetail" type="hidden">

        <input name="inputCn" id="inputCn" type="hidden">
        <input name="input" id="input" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label">农事名称：</label>
            <div class="col-sm-8">
                <input id="workName" name="workName" required class="form-control" type="text">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">农事类型：</label>
            <div class="col-sm-8">
                <select id="workType" name="workType" required class="form-control m-b">
                    <option value="1">栽培</option>
                    <option value="2">农资</option>
                </select>
            </div>
        </div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">农事类型：</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" name="workType" checked="checked" value="1"/> 栽培 </label>
                <label class="radio-box"> <input type="radio" name="workType" value="2"/> 农资 </label>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">动态调整</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" name="isDynamic" checked value="1"/> 是 </label>
                <label class="radio-box"> <input type="radio" name="isDynamic" value="2"/> 不是 </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">第几天开始：</label>
            <div class="col-sm-8">
                <input id="workStart" name="workStart"  class="form-control" required type="number">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">循环周期(天)：</label>
            <div class="col-sm-8">
                <input id="cycleDays" name="cycleDays" class="form-control" type="number">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">第几天结束：</label>
            <div class="col-sm-8">
                <input id="workEnd" name="workEnd" class="form-control" type="number">
            </div>
        </div>

        <!--<div class="form-group">
            <label class="col-sm-3 control-label">农资名称：</label>
            <div class="col-sm-8">
                <input id="inputCn" name="inputCn" class="form-control" type="text">
            </div>
        </div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label ">农资名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectMeterialTree()" id="treeName"
                           readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">数量/亩：</label>
            <div class="col-sm-8">
                <input id="inputCount" name="inputCount" class="form-control" type="number" step="0.1">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">单位：</label>
            <div class="col-sm-8">
                <select id="inputUnit" name="inputUnit" required class="form-control m-b"
                        th:with="type=${@dict.getType('unitType')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工作内容：</label>
        </div>
        <div class="form-group">
            <div id="editor" type="text/plain" style="width:1024px;height:500px;"></div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" class="form-control valid" type="text" rows="4"></textarea>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" charset="utf-8" th:src="@{/ueditor/ueditor.config.js}"></script>
<script type="text/javascript" charset="utf-8" th:src="@{/ueditor/ueditor.all.js}"></script>
<script type="text/javascript">
    //  自定义方法
    jQuery.validator.addMethod("isBig", function(value,element) {
       var start = $("#workStart").val();
       if(start != ""){
           if(value == ""){
               return true;
           }
           return this.optional(element) ||(value >= start);
       }
      return true;
    }, "结束天数不能小于开始天数");
    jQuery.validator.addMethod("isSmall", function(value,element) {
        var start = $("#workEnd").val();
        if(start != ""){
            return this.optional(element) ||(value <= start);
        }
        return true;
    }, "开始天数不能大于等于结束天数");

    var prefix = ctx + "system/ncWork"
   $("#form-ncWork-add").validate({
        rules: {
            workStart: {
                number:true,
                digits:true,
                isSmall:true,
                min:0
            },
            workEnd: {
                number:true,
                digits:true,
                isBig:true,
                min:0
            },
            cycleDays:{
                number:true,
                digits:true,
                min:0
            },
            workName:{
                required:true
            }
        },
        messages: {
            cycleDays: {
                digits:"请输入正整数"
            },
            workEnd: {
                digits:"请输入正整数"
            },
            workStart: {
                digits:"请输入正整数"
            },
            workName:{
                required:"农事名称不能为空"
            }
        },
        focusCleanup: true
    });


    function submitHandler() {
        $('#workDetail').val(ue.getContent());

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-ncWork-add').serialize());
            }


    }


    var ue = UE.getEditor('editor', {
        initialFrameWidth: 755,
        initialFrameHeight: 600
    });

    $(function () {
        $("#treeName").parents(".form-group").hide();
        $("#inputCount").parents(".form-group").hide();
        $("#inputUnit").parents(".form-group").hide();
        $('input').on('ifChecked', function (event) {
            if ($(event.target).attr('name') == 'workType') {
                var workType = $(event.target).val();
                if (workType == "1") {//农事
                    $("#treeName").parents(".form-group").hide();
                    $("#inputCount").parents(".form-group").hide();
                    $("#inputUnit").parents(".form-group").hide();

                } else if (workType == "2") {//农资
                    $("#treeName").parents(".form-group").show();
                    $("#inputCount").parents(".form-group").show();
                    $("#inputUnit").parents(".form-group").show();

                }
            }
        });
    });

    /*农资树*/
    function selectMeterialTree() {
        var prefix = ctx + "system/meterial";
        var options = {
            title: '农资选择',
            width: "380",
            url: prefix + "/selectMeterialTree/141",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#input").val(body.find('#treeId').val());
        $("#inputCn").val(body.find('#treeName').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>
